<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:widget="http://www.netvibes.com/ns/">
<head>
	<title>BBC:ON THIS DAY</title>
	<link rel="icon" href="http://www.bbc.co.uk/favicon.ico" type="image/x-icon" />
	<meta name="title" content="BBC:ON THIS DAY" />
	<meta name="author" content="ehaagwlke" />
	<meta name="website" content="http://bbc.co.uk/" />
	<meta name="description" content="采用BBC网站的On this day in history 制作。喜欢就加。标题会自适应宽度，改变widget在页面上的位置后请及时刷新页面或者widget" />
	<meta name="version" content="1.0.1" />
	<meta name="keyword" content="on this day in history" />
	<meta name="thumbnail" content="http://news.bbc.co.uk/nol/shared/img/bbc_news_120x60.gif" />
	<meta name="screenshot" content="http://1821.img.pp.sohu.com.cn/images/2008/6/19/16/4/11b450290ea.jpg" />
	<meta name="debugMode" content="false" />


	
	<widget:preferences>
		<preference type="text" name="title" label="Tilte" onchange="true"  />
		<preference type="text" name="items" label="Items" onchange="true" />
	</widget:preferences>

	<script type="text/javascript">
		//<![CDATA[
			
			var itemNum = '';   //variable hold the amount of items that to displayed, max is 50, default is 10.


			widget.dataInt = function() {
				UWA.Data.getXml(
					'http://news.bbc.co.uk/rss/on_this_day/front_page/rss.xml',
					widget.dataProcessor
					);
			}
		
			
		 
			widget.dataProcessor = function(xml) {
				//set the number of items to be displayed
				if(widget.getValue("items")){			
					itemNum = widget.getValue("items");
				}
				
				widget.body.empty();
				widget.setBody('<div class="rich_list"></div>');
				var el = UWA.$element(widget.body.getElementsByTagName('div')[0]);
				var w = el.getDimensions().width;
				titleLen = Math.floor(w*0.8/7);
				
				
				var rootNode = xml.documentElement;
		
				var contentItems = rootNode.getElementsByTagName('item');
				
				//calculate the max of items to be displayed
				if(itemNum && itemNum <= 50 && itemNum > 0 ) {
					var itemMaxNum = itemNum;
				}else{
					var itemMaxNum = 5;
				}

				var opContent = ''; 

				//extract the contents from the xml document
				for(i=0;i<itemMaxNum;i++){

						var title = contentItems[i].getElementsByTagName("title")[0].firstChild.nodeValue;
						var time = contentItems[i].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
						var link = contentItems[i].getElementsByTagName('link')[0].firstChild.nodeValue;
						var description = contentItems[i].getElementsByTagName('description')[0].firstChild.nodeValue;
					
						var opTime = time.substr(5,11);
						
						if(title.length > titleLen) { var nTitle = title.substr(0,titleLen-1)+'...';} else { var nTitle = title; }
						opContent += ' <div class="item"><h3>'+(i+1)+'. <a href="'+link+'" target="_blank" title="'+title+'">'+nTitle+'</a></h3><p class="description">(<i>'+opTime+'</i>)  '+description+'<b>  <a href="'+link+'" target="_blank"><em>continue</em></a></b></p></div>';
				}

					opContent += '<p style="float:right;border-bottom:1px dashed"><a href="http://news.bbc.co.uk/onthisday/default.stm" target="_blank">数据来源</a></p>';

				if(widget.getValue("title")){
					var title = widget.getValue("title");
					widget.setTitle(title);
				}else{
					widget.setTitle("BBC:ON THIS DAY");
				}
			
				el.innerHTML = opContent;
				
			}
			
			widget.onLoad = function(){
				widget.dataInt();
			}
			
			widget.onRefresh = function() {
				widget.body.empty();
				widget.setBody('<div class="content">Loading data.....</div>');
				widget.dataInt();
			}

			widget.onResize = function(){
				widget.body.empty();
				widget.setBody('<div class="content">Loading data.....</div>');
				widget.dataInt();
			}
			
		//]]>
	</script>
</head>
<body>
	
	<div class="content">Loading data.....</div>
	

</body>
</html>
